<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="__static/lib/layui-v2.5.5/css/layui.css" media="all">
	<link rel="stylesheet" href="__static/css/public.css" media="all">
	
	<style>
		.layui-form-pane .layui-form-label {
			width: 90px;
		}
		
	</style>
</head>
<body>
<div class="layuimini-container">
	<div class="layuimini-main">
		<fieldset class="table-search-fieldset">
			<legend>搜索信息</legend>
			<form class="layui-form layui-form-pane" action="">
				<div class="layui-form-item" style="margin-bottom: 5px;">
					<div class="layui-inline">
						<label class="layui-form-label">客户名称</label>
						<div class="layui-input-inline">
							<select name="customer_id" lay-search="" autocomplete="off">
								<option value="" >直接选择或搜索选择</option>
								{volist name="cu_list" id="cu"}
									<option value="{$cu.id}" >{$cu.name}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">媒介</label>
						<div class="layui-input-inline">
							<select name="media_id" lay-search="" autocomplete="off">
								<option value="" >直接选择或搜索选择</option>
								{volist name="m_list" id="cu"}
									<option value="{$cu.id}" >{$cu.username}</option>
								{/volist}
					        </select>
						</div>
					</div>
					<div class="layui-inline">
						<button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
					</div>
				</div>
			</form>
		</fieldset>

		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

		<script type="text/html" id="currentTableBar">
			
			<a style="{{d.status!=2?'display:none;':''}}" class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">出纳</a>
			<a style="{{d.status!=2?'display:none;':''}}" class="layui-btn layui-btn-xs layui-btn-danger" lay-event="reject">驳回</a>
		</script>
		<script type="text/html" id="statusTable">
			<span onmouseover=get_msg(this) data-msg="{{d.reject}}"  style="color: red;font-weight: bold;{{d.status == 0?'':'display:none;'}}">驳回</span>
			<span  style="color: #03A9F4;font-weight: bold;{{d.status == 1?'':'display:none;'}}">未回款</span>
			<span  style="color: #ff9800;font-weight: bold;{{d.status == 2?'':'display:none;'}}">审核中</span>
			<span  style="color: #4CAF50;font-weight: bold;{{d.status == 3?'':'display:none;'}}">已回款</span>
		</script>
	</div>
</div>
<script src="__static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="__static/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
function get_msg(obj){
	var str = $(obj).attr('data-msg');
	layer.tips(str,$(obj));
}

//出纳
function get_cashier(id){
	layer.open({
        type: 2,
        title:'出纳确认',
        area: ['50%', '70%'],
        fixed: false, //不固定
        maxmin: true,
        shadeClose:false,	//点击遮罩后关闭提示框
        scrollbar:false, //- 是否允许浏览器出现滚动
        content: "{:url('return_money_cashier')}?id="+id 
    });
    //layer.full(index);
} 
	var form,table,laydate
	layui.use(['form', 'table', 'tableSelect', 'laydate'], function () {
		$ = layui.jquery , form = layui.form , table = layui.table , laydate = layui.laydate
		laydate.render({
		    elem: '#date' //指定元素
		  });
		table.render({
			elem: '#currentTableId',
			height: $(window).height() - 150,
			id:'return_money',
			url: '{:url("return_money", ["t"=>"json"])}',
			method : 'post',
			toolbar: true,
			totalRow: true,
			cols: [[
				{ field: 'customer_name', title: '客户名称',width:100, totalRowText: '合计'},
				{ field: 'amount', title: '垫款金额' ,width:100, totalRow: true},
				
				{ field: 'media_name', title: '媒介',width:180},
				{ field: 'num', title: '公司银行账户',width:180},
				{ field: 'bank_address', title: '开户行',width:180},
				{ field: 'account_name', title: '银行户主',width:180},
				{ field: 'type', title: '银行类型',width:100,templet:function(d){
					return d.type?'对公':'对私'
				}},
				{ field: 'returned_money_url', title: '回款凭证',width:100,templet:function(d){
					return d.returned_money_url?'<img src="'+d.returned_money_url+'">':''
				}},
				{ field: 'finance_url', title: '财务凭证',width:100,templet:function(d){
					return d.finance_url?'<img src="'+d.finance_url+'">':''
				}},
				{ field: 'status', title: '状态',toolbar:'#statusTable',width:100 },
				{ field: 'note', title: '备注' ,width:200},
				{ field: 'create_time', title: '垫款时间' ,width:180},
				{ title: '操作',fixed: 'right', toolbar: '#currentTableBar', align: "center",width:130 }
			]],
			
			limit: 30,
			page: true,
			skin: 'line',
			even: true
		});

		//监听操作栏事件
		table.on('tool(currentTableFilter)', function (obj) {
			var data = obj.data;
			switch (obj.event) {
				case 'edit':
					get_cashier(data.id);
				break;
				
				case 'reject':
					get_bohuis(data.id);
				break;
			}
			
		});
		
		
		//驳回
		function get_bohuis(id){
			layer.prompt({
				  formType: 2,
				  title: '驳回原因',
				  area: ['350px', '150px'] //自定义文本域宽高
				}, function(value, index, elem){
					layer.load(1, { shade : [ 0.5, '#676a6c' ] });
					$.post("{:url('get_return_moner_buohui')}?t=json",{id:id,reject:value},function(data){
					 	layer.closeAll();
						if (data['code'] == 1) {
							get_load(data['msg']);
						} else {
							layer.msg(data['msg'], { icon : 5 });
						}
					})
				});
			 
		}
		//监听行单击事件
		table.on('row(currentTableFilter)', function(obj){
			  layer.photos({
				  photos: obj.tr
				  ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
				});
			});
		
		
		//搜索
		form.on('submit(data-search-btn)', function(data){
			var articleFrom = data.field;
			table.reload('return_money', {
			  	url: '{:url("return_money", ["t"=>"json"])}',
				where:articleFrom
			});
			return false;
		  });
	});
	//重载数据表
	function get_load(msg){
		table.reload('return_money', {
			  url: '{:url("return_money", ["t"=>"json"])}',
			});
		layer.msg(msg, {icon: 6});
	}
</script>

</body>
</html>